require("dotenv").config();
const e = require("cors");
const jwt = require('jsonwebtoken');

const secret = process.env.jwt_secret;
const expiresIn = process.env.jwt_expires_in;

// 生成 Token
const generateToken = (payload) => {
    console.log(expiresIn)
    // 生成 token
    const token = jwt.sign(
        payload,
        secret,
        { 
            expiresIn: expiresIn,
        }
    );
    return token;
};

// 验证并解码 Token
const verifyToken = (token) => {
    return jwt.verify(token, secret);
};



module.exports = {
    generateToken,
    verifyToken,
};